package StudyCode.summary.myfile;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertByteToStringLength8 {
	public static void main(String[] argv) {
		byte b = 2;
		System.out.println(bitStringFromByte(b));
	}

	private static String bitStringFromByte(byte b) {
		String tail = Integer.toBinaryString(b & 0xFF).replace(' ', '0');
		int tailLen = tail.length();
		for (int i = 0; i < 8 - tailLen; i++) {
			tail = "0".concat(tail);
		}
		return tail;
	}
}
